package com.enjoy.stack;

import java.util.Scanner;

public class KuoHaoStack {

    public static boolean isOk(String s) {
        MyStack<Character> bracket = new EnjoyMyStack<>(20);
        char[] chars = s.toCharArray();
        Character top;
        for (char c : chars) {
            switch (c) {
                case '{':
                case '(':
                case '[':
                    bracket.push(c);
                    break;
                case '}':
                    top = bracket.pop();
                    if (top == null) {
                        return false;
                    }
                    if (top == '{') {
                        break;
                    } else {
                        return false;
                    }
                case ')':
                    top = bracket.pop();
                    if (top == null) {
                        return false;
                    }
                    if (top == '(') {
                        break;
                    } else {
                        return false;
                    }
                case ']':
                    top = bracket.pop();
                    if (top == null) {
                        return false;
                    }
                    if (top == '[') {
                        break;
                    } else {
                        return false;
                    }
                default:
                    break;
            }
        }
        return bracket.isEmpty();
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String s = scanner.next();
            System.out.println("匹配的结果 = " + isOk(s));
        }


    }
}
